using System;
using StaffWarsFm.Lib.Data;
using StaffWarsFm.Lib.Services;

namespace StaffWarsFm.Questions
{
    public class DemoQuestionService : IQuestionService
    {
        private static int count = 0;

        private Question[] Questions
        {
            get
            {
                return new[]
                {
                    GetAlbumYearQuestion(), 
                    GetNumTracksQuestion(), 
                    GetWhatTrackOnAlbumQuestion(),
                    GetWikiQuestion(), 
                    GetFactQuestion()
                };
            }
        }

        public Question GenerateQuestion(User[] players, User[] connectedUsers)
        {
            if(count >= Questions.Length)
            {
                throw new Exception();
            }

            var q = Questions[count];

            count++;

            return q;
        }

        public Question[] GenerateQuestion(User[] players, User[] connectedUsers, int count)
        {
            return new[]
            {
                GenerateQuestion(players, connectedUsers), 
                GenerateQuestion(players, connectedUsers),
                GenerateQuestion(players, connectedUsers),
                GenerateQuestion(players, connectedUsers),
                GenerateQuestion(players, connectedUsers)
            };
        }

        private Question GetAlbumYearQuestion()
        {
            var answers = new[]
            {
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/174s/12441259.jpg", IsCorrect = true, Text = "In Rainbows"},
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/174s/11396311.jpg", IsCorrect = false, Text = "Ok Computer" },
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/174s/11498407.jpg", IsCorrect = false, Text = "Pablo Honey" },
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/174s/14192921.jpg", IsCorrect = false, Text = "The Bends" }
            };

            return new Question()
            {
                Text = "What album did Radiohead release in 2007?",
                Answers = answers,
                ImageUrl = "http://userserve-ak.last.fm/serve/126/5801617.jpg"
            };
        }

        private Question GetNumTracksQuestion()
        {
            var answers = new[]
            {
                new Answer { ImageUrl= "", IsCorrect = false, Text = "10"},
                new Answer { ImageUrl = "", IsCorrect = false, Text = "14"},
                new Answer { ImageUrl = "", IsCorrect =  false, Text = "11"},
                new Answer { ImageUrl = "", IsCorrect = true, Text = "13"}
            };

            return new Question
            {
                ImageUrl = "http://userserve-ak.last.fm/serve/126/10973789.jpg",
                Text = "How many tracks does Alligator by The National have?",
                Answers = answers
            };
        }

        private Question GetWhatTrackOnAlbumQuestion()
        {
            var answers = new[]
            {
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/174s/12441259.jpg", IsCorrect = false, Text = "In Rainbows"},
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/174s/11396311.jpg", IsCorrect = true, Text = "Ok Computer" },
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/174s/11498407.jpg", IsCorrect = false, Text = "Pablo Honey" },
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/174s/14192921.jpg", IsCorrect = false, Text = "The Bends" }
            };

            return new Question
            {
                ImageUrl = "http://userserve-ak.last.fm/serve/126/5801617.jpg",
                Text = "What album, by Radiohead, is the track Paranoid Android on?",
                Answers = answers
            };
        }

        private Question GetWikiQuestion()
        {
            var answers = new[]
            {
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/252/216737.jpg", IsCorrect = false, Text = "The Smashing Pumpkins"},
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/252/10973789.jpg", IsCorrect = true, Text = "The National" },
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/252/121888.jpg", IsCorrect = false, Text = "Modest Mouse" },
                new Answer { ImageUrl = "http://userserve-ak.last.fm/serve/252/4264387.jpg", IsCorrect = false, Text = "Avril Lavigne" }
            };

            return new Question
            {
                ImageUrl = "",
                Text = "Whoir self-titled debut album \"Who National\" (Brassland 2001) was recorded and released before they had played even a single show?",
                Answers = answers
            };
        }

        private Question GetFactQuestion()
        {
            var answers = new[]
            {
                new Answer { ImageUrl = "", IsCorrect = false, Text = "2005"},
                new Answer { ImageUrl = "", IsCorrect = true, Text = "2006" },
                new Answer { ImageUrl = "", IsCorrect = false, Text = "2007" },
                new Answer { ImageUrl = "", IsCorrect = false, Text = "2008" }
            };

            return new Question
            {
                ImageUrl = "http://userserve-ak.last.fm/serve/252/17155403.png",
                Text = "What year did Leona Lewis form?",
                Answers = answers
            };
        }

        //private Question GetAlbumArtworkQuestion()
        //{
            
        //}
    }
}